Objects.copy   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
c 1
b 0
f 0
nc 1
nop 1
dl 0
loc 3
rs 10
1
var Objects = {
2
  merge: function (a, b) {
3
    if (typeof b === 'undefined' || b === null) {
4
      return a
5
    }
6
    if (typeof b !== 'object' || typeof a !== 'object' || a === null) {
7
      return b
8
    }
9
    if (Array.isArray(a) || Array.isArray(b)) {
10
      return b
11
    }
12
    var target = {}
13
    Object.keys(a).forEach(function (key) {
14
      target[key] = a[key]
15
    })
16
    Object.keys(b).forEach(function (key) {
17
      target[key] = Objects.merge(target[key], b[key])
18
    })
19
    return target
20
  },
21
  copy: function (value) {
22
    if (typeof value !== 'object' || value === null) {
23
      return value
24
    }
25
    if (Array.isArray(value)) {
26
      return value.map(Objects.copy)
27
    }
28
    var target = {}
29
    Object.keys(value).forEach(function (key) {
30
      target[key] = Objects.copy(value[key])
31
    })
32
    return target
33
  }
34
}
35
36
module.exports = {
37
  Objects: Objects
38
}
39